/**
* 
* ====================================================================
*
* @author apov <apov@ymail.com>
*/ 
// ObjectPool.h
//
#pragma once

#include "BaseDefine.h"
#include "Thread.h"
#include <boost/pool/object_pool.hpp>

template <class T>
class ObjectPool{
public:
	T* alloc(){
		BlanketLock lock( &lock_ );	

		return pool_.construct();
	}

	bool free( T* t ){
		BlanketLock lock( &lock_ );	

		if(! t )
			return false;

		pool_.destroy( (T*)t );
		
		return true;
	}	

	ObjectPool(){	
	}

	virtual ~ObjectPool(){}

protected:

private:
	CLock lock_;

	boost::object_pool<T> pool_;	
};